<?php

namespace App\Http\Requests\Auth;

use App\Rules\NoChineseEmail;
use Illuminate\Foundation\Http\FormRequest;

class RegisterRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'email'     => ['required', 'string', 'email', 'max:255', 'unique:users', new NoChineseEmail()],
            'password'  => ['required', 'string', 'min:8', 'confirmed'],
            'country_id'=> ['required','exists:swt_country,id'],
            'code'      => ['required','string','size:6']
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'email.required'     => __('auth.email_required'),
            'email.email'        => __('auth.email_email'),
            'email.unique'       => __('auth.email_unique'),
            'password.required'  => __('auth.password_required'),
            'password.min'       => __('auth.password_min'),
            'password.confirmed' => __('auth.password_confirmed'),
            'code.required'      => __('auth.code_required'),
            'code.size'          => __('auth.code_size')
        ];
    }
}
